
package aesphere;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.io.File;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.net.URL;
import javax.help.HelpBroker;
import javax.help.HelpSet;

/**
 *
 * @author antonio
 */
public class MainAtaquesUI extends javax.swing.JFrame {

    private MainUI wpadre;
    private javax.swing.JFileChooser archivos;
    private MainAtaquesUI yo = null;

    /** Creates new form MainAtaquesUI */
    public MainAtaquesUI(MainUI padre) {
        initComponents();
        setLangLabels();
        setHelp();
        wpadre = padre;
        ButtonGroup group = new ButtonGroup();
        archivos = new JFileChooser();
        group.add(ClienteRadioButton);
        group.add(ServidorRadioButton);
        this.setSize(800, 710);
        this.setResizable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        entradaPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        cipherTextArea = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        plainTextArea = new javax.swing.JTextArea();
        plainLabel = new javax.swing.JLabel();
        cipherLabel = new javax.swing.JLabel();
        plainComboBox = new javax.swing.JComboBox();
        plainBrowseButton = new javax.swing.JButton();
        cipherComboBox = new javax.swing.JComboBox();
        cipherBrowseButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        EjecutarButton = new javax.swing.JButton();
        funcionamientoPanel = new javax.swing.JPanel();
        funcLabel = new javax.swing.JLabel();
        ServidorRadioButton = new javax.swing.JRadioButton();
        IPLabel = new javax.swing.JLabel();
        IPTextField = new javax.swing.JTextField();
        ClienteRadioButton = new javax.swing.JRadioButton();
        clientesLabel = new javax.swing.JLabel();
        NumeroClientesTextField = new javax.swing.JTextField();
        modoLabel = new javax.swing.JLabel();
        modoComboBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        monoCheckBox = new javax.swing.JCheckBox();
        BotonInfo = new javax.swing.JButton();
        Cancelar = new javax.swing.JButton();
        clavesPanel = new javax.swing.JPanel();
        ClaveInicialTextField = new javax.swing.JTextField();
        ClaveFinalTextField = new javax.swing.JTextField();
        claveInicialLabel = new javax.swing.JLabel();
        claveFinalLabel = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        formatoClavesLabel = new javax.swing.JLabel();
        clavesComboBox = new javax.swing.JComboBox();
        claveSizeComboBox = new javax.swing.JComboBox();
        nKeysTxtLabel = new javax.swing.JLabel();
        nKeysLabel = new javax.swing.JLabel();
        cifrarMenuBarMain = new javax.swing.JMenuBar();
        mainMenuArchivo = new javax.swing.JMenu();
        Salir = new javax.swing.JMenuItem();
        mainMenuEditar = new javax.swing.JMenu();
        menuCopiarClaro = new javax.swing.JMenuItem();
        menuCopiarCifrado = new javax.swing.JMenuItem();
        menuPegarClaro = new javax.swing.JMenuItem();
        menuPegarCifrado = new javax.swing.JMenuItem();
        mainMenuAyuda = new javax.swing.JMenu();
        Contenidos = new javax.swing.JMenuItem();
        acercade = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("AESphere - Ataques");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        entradaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ENTRADA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N

        cipherTextArea.setColumns(20);
        cipherTextArea.setLineWrap(true);
        cipherTextArea.setRows(5);
        cipherTextArea.setWrapStyleWord(true);
        cipherTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cipherTextAreaKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cipherTextAreaKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(cipherTextArea);

        plainTextArea.setColumns(20);
        plainTextArea.setLineWrap(true);
        plainTextArea.setRows(5);
        plainTextArea.setWrapStyleWord(true);
        plainTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                plainTextAreaKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                plainTextAreaKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(plainTextArea);

        plainLabel.setText("Texto en claro: ");

        cipherLabel.setText("Texto cifrado: ");

        plainComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Texto ASCII", "Hexadecimal", "Archivo" }));
        plainComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plainComboBoxActionPerformed(evt);
            }
        });

        plainBrowseButton.setText("Browse");
        plainBrowseButton.setEnabled(false);
        plainBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plainBrowseButtonActionPerformed(evt);
            }
        });

        cipherComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Base64", "Hexadecimal", "Archivo" }));
        cipherComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cipherComboBoxActionPerformed(evt);
            }
        });

        cipherBrowseButton.setText("Browse");
        cipherBrowseButton.setEnabled(false);
        cipherBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cipherBrowseButtonActionPerformed(evt);
            }
        });

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/botondef2.png"))); // NOI18N

        org.jdesktop.layout.GroupLayout entradaPanelLayout = new org.jdesktop.layout.GroupLayout(entradaPanel);
        entradaPanel.setLayout(entradaPanelLayout);
        entradaPanelLayout.setHorizontalGroup(
            entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(entradaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel5)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(entradaPanelLayout.createSequentialGroup()
                        .add(plainComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 114, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(plainBrowseButton))
                    .add(plainLabel)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 270, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(entradaPanelLayout.createSequentialGroup()
                        .add(cipherComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 111, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(cipherBrowseButton))
                    .add(cipherLabel)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 286, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(72, Short.MAX_VALUE))
        );
        entradaPanelLayout.setVerticalGroup(
            entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(entradaPanelLayout.createSequentialGroup()
                .add(entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(entradaPanelLayout.createSequentialGroup()
                        .add(entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(plainLabel)
                            .add(cipherLabel))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(plainComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(cipherComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(cipherBrowseButton)
                            .add(plainBrowseButton))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(entradaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jScrollPane2)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)))
                    .add(jLabel5))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        EjecutarButton.setText("Ejecutar");
        EjecutarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EjecutarButtonActionPerformed(evt);
            }
        });

        funcionamientoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "FUNCIONAMIENTO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N

        funcLabel.setText("Este equipo funcionará como:");

        ServidorRadioButton.setSelected(true);
        ServidorRadioButton.setText("Servidor");
        ServidorRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ServidorRadioButtonActionPerformed(evt);
            }
        });

        IPLabel.setText("Introduce la dirección IP del Servidor:");
        IPLabel.setEnabled(false);

        IPTextField.setEnabled(false);
        IPTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                IPTextFieldActionPerformed(evt);
            }
        });

        ClienteRadioButton.setText("Cliente");
        ClienteRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClienteRadioButtonActionPerformed(evt);
            }
        });

        clientesLabel.setText("Introduce el número de clientes:");

        modoLabel.setText("Selecciona el modo de cifrado:");

        modoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ECB", "CBC" }));
        modoComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modoComboBoxActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/botondef1.png"))); // NOI18N

        monoCheckBox.setText("Monousuario");
        monoCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monoCheckBoxActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout funcionamientoPanelLayout = new org.jdesktop.layout.GroupLayout(funcionamientoPanel);
        funcionamientoPanel.setLayout(funcionamientoPanelLayout);
        funcionamientoPanelLayout.setHorizontalGroup(
            funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(funcionamientoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel2)
                .add(33, 33, 33)
                .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(funcLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 198, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(funcionamientoPanelLayout.createSequentialGroup()
                        .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(ServidorRadioButton)
                            .add(ClienteRadioButton))
                        .add(37, 37, 37)
                        .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(clientesLabel)
                            .add(modoLabel)
                            .add(IPLabel))
                        .add(35, 35, 35)
                        .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(IPTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(funcionamientoPanelLayout.createSequentialGroup()
                                .add(NumeroClientesTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 41, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(18, 18, 18)
                                .add(monoCheckBox, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(modoComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(151, Short.MAX_VALUE))
        );
        funcionamientoPanelLayout.setVerticalGroup(
            funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(funcionamientoPanelLayout.createSequentialGroup()
                .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(funcionamientoPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(funcLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(ServidorRadioButton)
                            .add(clientesLabel)
                            .add(NumeroClientesTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(monoCheckBox))
                        .add(6, 6, 6)
                        .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(modoLabel)
                            .add(modoComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(funcionamientoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(IPTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(IPLabel)
                            .add(ClienteRadioButton)))
                    .add(jLabel2))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        BotonInfo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/info.png"))); // NOI18N
        BotonInfo.setBorder(null);
        BotonInfo.setContentAreaFilled(false);
        BotonInfo.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        Cancelar.setLabel("Cancelar");
        Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelarActionPerformed(evt);
            }
        });

        clavesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ESPACIO DE CLAVES", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N

        ClaveInicialTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                ClaveInicialTextFieldKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ClaveInicialTextFieldKeyTyped(evt);
            }
        });

        ClaveFinalTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClaveFinalTextFieldActionPerformed(evt);
            }
        });
        ClaveFinalTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                ClaveFinalTextFieldKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ClaveFinalTextFieldKeyTyped(evt);
            }
        });

        claveInicialLabel.setText("Clave inicial: ");

        claveFinalLabel.setText("Clave final:  ");

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/botondef3.png"))); // NOI18N

        formatoClavesLabel.setText("Formato de claves:");

        clavesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Hexadecimal", "ASCII" }));
        clavesComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clavesComboBoxActionPerformed(evt);
            }
        });

        claveSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "128 bits", "192 bits", "256 bits" }));
        claveSizeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                claveSizeComboBoxActionPerformed(evt);
            }
        });

        nKeysTxtLabel.setText("claves a probar");

        nKeysLabel.setText("0");
        nKeysLabel.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                nKeysLabelPropertyChange(evt);
            }
        });

        org.jdesktop.layout.GroupLayout clavesPanelLayout = new org.jdesktop.layout.GroupLayout(clavesPanel);
        clavesPanel.setLayout(clavesPanelLayout);
        clavesPanelLayout.setHorizontalGroup(
            clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(clavesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel9)
                .add(18, 18, 18)
                .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(claveInicialLabel)
                    .add(claveFinalLabel))
                .add(18, 18, 18)
                .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(clavesPanelLayout.createSequentialGroup()
                        .add(nKeysLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(nKeysTxtLabel))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, clavesPanelLayout.createSequentialGroup()
                        .add(formatoClavesLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 263, Short.MAX_VALUE)
                        .add(clavesComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(claveSizeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(ClaveInicialTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
                    .add(ClaveFinalTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))
                .addContainerGap())
        );
        clavesPanelLayout.setVerticalGroup(
            clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(clavesPanelLayout.createSequentialGroup()
                .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel9)
                    .add(clavesPanelLayout.createSequentialGroup()
                        .add(4, 4, 4)
                        .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(formatoClavesLabel)
                            .add(claveSizeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(clavesComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(claveInicialLabel)
                            .add(ClaveInicialTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(claveFinalLabel)
                            .add(ClaveFinalTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .add(18, 18, 18)
                .add(clavesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nKeysLabel)
                    .add(nKeysTxtLabel))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, funcionamientoPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, entradaPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(Cancelar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(EjecutarButton)
                        .add(18, 18, 18)
                        .add(BotonInfo))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, clavesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(funcionamientoPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(entradaPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(clavesPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(BotonInfo)
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(EjecutarButton)
                        .add(Cancelar)))
                .addContainerGap(104, Short.MAX_VALUE))
        );

        mainMenuArchivo.setText("Archivo");

        Salir.setText("Salir");
        Salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SalirActionPerformed(evt);
            }
        });
        mainMenuArchivo.add(Salir);

        cifrarMenuBarMain.add(mainMenuArchivo);

        mainMenuEditar.setText("Editar");

        menuCopiarClaro.setText("Copiar claro");
        menuCopiarClaro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuCopiarClaroActionPerformed(evt);
            }
        });
        mainMenuEditar.add(menuCopiarClaro);

        menuCopiarCifrado.setText("Copiar cifrado");
        menuCopiarCifrado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuCopiarCifradoActionPerformed(evt);
            }
        });
        mainMenuEditar.add(menuCopiarCifrado);

        menuPegarClaro.setText("Pegar claro");
        menuPegarClaro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPegarClaroActionPerformed(evt);
            }
        });
        mainMenuEditar.add(menuPegarClaro);

        menuPegarCifrado.setText("Pegar cifrado");
        menuPegarCifrado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPegarCifradoActionPerformed(evt);
            }
        });
        mainMenuEditar.add(menuPegarCifrado);

        cifrarMenuBarMain.add(mainMenuEditar);

        mainMenuAyuda.setText("Ayuda");

        Contenidos.setText("Contenidos");
        Contenidos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ContenidosActionPerformed(evt);
            }
        });
        mainMenuAyuda.add(Contenidos);

        acercade.setText("Acerca de");
        mainMenuAyuda.add(acercade);

        cifrarMenuBarMain.add(mainMenuAyuda);

        setJMenuBar(cifrarMenuBarMain);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /*
     * Set all the title elements
     */
    private void setLangLabels () {
        this.setTitle(Entorno.getTrans("Att.title"));
        funcionamientoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), Entorno.getTrans("Att.funcTit").toUpperCase(), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18)));
        entradaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), Entorno.getTrans("Att.inTit").toUpperCase(), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18)));
        clavesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), Entorno.getTrans("Att.keyTit").toUpperCase(), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18)));
        funcLabel.setText(Entorno.getTrans("Att.funcTxt"));
        ServidorRadioButton.setText(Entorno.getTrans("Att.serv"));
        ClienteRadioButton.setText(Entorno.getTrans("Att.client"));
        clientesLabel.setText(Entorno.getTrans("Att.nCliTxt"));
        modoLabel.setText(Entorno.getTrans("Att.modeTxt"));
        IPLabel.setText(Entorno.getTrans("Att.ipTxt"));
        modoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Entorno.getTrans("Att.ecb"), Entorno.getTrans("Att.cbc") }));
        plainLabel.setText(Entorno.getTrans("AES.plain"));
        cipherLabel.setText(Entorno.getTrans("AES.cipher"));
        plainComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Entorno.getTrans("AES.asciTxt"), Entorno.getTrans("AES.hex"), Entorno.getTrans("gen.file") }));
        cipherComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Entorno.getTrans("AES.64"), Entorno.getTrans("AES.hex"), Entorno.getTrans("gen.file") }));
        plainBrowseButton.setText(Entorno.getTrans("gen.browse"));
        cipherBrowseButton.setText(Entorno.getTrans("gen.browse"));
        formatoClavesLabel.setText(Entorno.getTrans("Att.keyFormatTxt"));
        claveInicialLabel.setText(Entorno.getTrans("Att.key1Txt"));
        claveFinalLabel.setText(Entorno.getTrans("Att.key2Txt"));
        clavesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Entorno.getTrans("AES.hex"), Entorno.getTrans("AES.asci") }));
        claveSizeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Entorno.getTrans("AES.128"), Entorno.getTrans("AES.192"), Entorno.getTrans("AES.256") }));        
        Cancelar.setText(Entorno.getTrans("gen.cancel"));
        EjecutarButton.setText(Entorno.getTrans("gen.exec"));
        mainMenuArchivo.setText(Entorno.getTrans("gen.file"));
        mainMenuEditar.setText(Entorno.getTrans("gen.edit"));
        mainMenuAyuda.setText(Entorno.getTrans("gen.help"));
        Salir.setText(Entorno.getTrans("gen.exit"));
        menuCopiarClaro.setText(Entorno.getTrans("Att.copyPlain"));
        menuPegarClaro.setText(Entorno.getTrans("Att.pastePlain"));
        menuCopiarCifrado.setText(Entorno.getTrans("Att.copyCipher"));
        menuPegarCifrado.setText(Entorno.getTrans("Att.pasteCipher"));
        Contenidos.setText(Entorno.getTrans("gen.cont"));
        acercade.setText(Entorno.getTrans("gen.about"));
        nKeysLabel.setText("");
        nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));
        monoCheckBox.setText(Entorno.getTrans("Att.mono"));
    }
    
    private void setHelp () {

        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension ventana = getSize();

        try {
            File fichero = null;

            if (Entorno.getProperty("language").equals("ES"))
                fichero = new File("help/help_set_ES.hs");
            else if (Entorno.getProperty("language").equals("EN"))
                fichero = new File("help/help_set_EN.hs");
            URL hsURL = fichero.toURI().toURL();
            HelpSet helpset = new HelpSet(getClass().getClassLoader(), hsURL);
            HelpBroker hb = helpset.createHelpBroker();
            hb.setLocation(new java.awt.Point((pantalla.width - ventana.width) / 2,
                                (pantalla.height - ventana.height) / 2));
            hb.setSize(new java.awt.Dimension(800, 628));
            hb.enableHelpOnButton(Contenidos, "ventana_ataques", helpset);
            hb.enableHelpOnButton(BotonInfo, "ventana_ataques", helpset);
            hb.enableHelpOnButton(acercade, "aplicacion", helpset);
        }

        catch (Exception e) {
             JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.helpErrMsg"), 
                     Entorno.getTrans("gen.helpErrTitle"), JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private boolean ComprobarDatos () {

        boolean aux = true;        
        int plainIndex = plainComboBox.getSelectedIndex();
        int cipherIndex = cipherComboBox.getSelectedIndex();

        if ( aux && (plainTextArea.getText().isEmpty() || cipherTextArea.getText().isEmpty()) ){
           JOptionPane.showMessageDialog(this, Entorno.getTrans("AES.fillWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
           aux=false;
        }

        if ( aux && !monoCheckBox.isSelected() && NumeroClientesTextField.getText().isEmpty() ){
           JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.nCliWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
           aux=false;
        }        

        if ( aux && !monoCheckBox.isSelected() && !comprobarNumero(NumeroClientesTextField.getText()) ) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cliNumberWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        } else if ( aux && !monoCheckBox.isSelected() && (Integer.parseInt(NumeroClientesTextField.getText()) <= 0) ) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cliNumberNegWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (plainIndex == 0) && (plainTextArea.getText().length() > 1024) ) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.plainMaxCharWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (plainIndex == 1) && (plainTextArea.getText().length() > 2048)) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.plainMaxHexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if (aux &&  (cipherIndex == 1) && (cipherTextArea.getText().length() < 32) ) {
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherMinHexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            aux=false;
        }

        if (aux && (cipherIndex == 0) && (cipherTextArea.getText().length() < 24) ) {
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherMinCharWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            aux=false;
        }

        if (aux &&  (cipherIndex == 1) && (cipherTextArea.getText().length() % 32 != 0)) {
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherMulHexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            aux=false;
        }

        //el texto cifrado será de como máximo 1024 + 16 = 1040 bytes = 1388 caracteres en Base64
        if ( aux && (cipherIndex == 0) && (cipherTextArea.getText().length() > 1388)) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherMax64WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (cipherIndex == 1) && (cipherTextArea.getText().length() > 2080)) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherMaxHexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (plainIndex == 1) && !ComprobarHexadecimal(plainTextArea.getText())) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.plainHexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (plainIndex == 2) && !comprobarArchivo(plainTextArea.getText(), 41943040) )
            aux = false;

        if (aux && (cipherIndex == 0) && !comprobarBase64(cipherTextArea.getText())) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipher64FormatWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if (aux && (cipherIndex == 0) && !comprobarBase64Length(cipherTextArea.getText())) {
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipher64LenWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            aux=false;
        }

        if ( aux && (cipherIndex == 1) && !ComprobarHexadecimal(cipherTextArea.getText())) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherHexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (cipherIndex == 2) && !comprobarArchivo(cipherTextArea.getText(), 41943056) )
            aux = false;

        return aux;
    }

    private boolean comprobarBase64Length (String base64) {
        //declaramos variable para almacenar el numero de caracteres sin relleno
        int len = 0;
        for (int i = base64.length() - 1; i >= 0; i--) {
            if (base64.charAt(i) != '=') len = i + 1;
        }
        if (len == 0) return false;

        if ( ((len * 3/4) % 16) != 0) return false;
        //si no se ha salido aún, es correcto
        return true;
    }

    private boolean comprobarBase64 (String base64) {
        boolean aux = true;
        int len = base64.length();
        //llevamos un contador para comprobar la longitud del string sin '/n' ni '/r'
        int count = 0;
        for (int i = 0; aux && (i < len); i++) {
            char letra = base64.charAt(i);

            if ( ((letra >= 'A') && (letra <= 'Z')) ||
                    ((letra >= 'a') && (letra <= 'z')) ||
                    ((letra >= '0') && (letra <= '9')) ||
                    (letra == '=') || (letra == '/') || (letra == '+') );
            else {
                if ( (letra == '\r') || (letra == '\n') ) //Si es salto de línea aumentamos el contador
                    count++;
                else aux = false;
            }
        }

        //si el número de caracteres (excluyendo salto de línea) no es múltiplo de 4, no es correcto
        if (aux && ((len - count) % 4 != 0) ) aux = false;

        return aux;
    }

    private boolean comprobarNumero (String num) {
        boolean aux = true;

        for (int i = num.length(); aux && (--i >= 0);) {
            char c = num.charAt(i);
            if (c < '0' || c > '9') aux = false;
        }

        return aux;
    }

    private boolean comprobarArchivo (String ruta, long max) {
        boolean aux = true;
        try {
            File arch = new File (ruta);
            if (!arch.exists()) {
                JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.fileNot1") 
                        + " " + ruta + " " + Entorno.getTrans("gen.fileNot2"),
                        Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
                aux = false;
            } else {
                if (arch.length() > max) {
                    aux = false;
                    JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.fileNot1")
                            + " " + ruta + " " + Entorno.getTrans("gen.fileNotLen"),
                        Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
                }
                /*
                 * si estamos comprobando descifrado y el tamaño no es mayor o
                 * múltiplo de 16 bytes, tamaño incorrecto
                 */
                if (aux && (max == 41943056) && 
                        ( (arch.length() < 16) || (arch.length() % 16 != 0) ) ) {
                    aux = false;
                    JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.fileNot1")
                            + " " + ruta + " " + Entorno.getTrans("gen.fileBadSize"),
                        Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE); 
                }
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.fileErr") +
                    ruta, Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
            aux = false;
        }
        return aux;
    }

    private void SalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SalirActionPerformed

        this.dispatchEvent(new java.awt.event.WindowEvent(this, java.awt.event.WindowEvent.WINDOW_CLOSING));
}//GEN-LAST:event_SalirActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        //wpadre.setEnabled(true);
        wpadre.requestFocus();
        wpadre.wclosed(this);
    }//GEN-LAST:event_formWindowClosing

    private void ServidorRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ServidorRadioButtonActionPerformed
        IPTextField.setEnabled(false);
        IPLabel.setEnabled(false);
        clavesPanel.setEnabled(true);
        entradaPanel.setEnabled(true);
        cipherTextArea.setEnabled(true);
        ClaveFinalTextField.setEnabled(true);
        ClaveInicialTextField.setEnabled(true);
        plainTextArea.setEnabled(true);
        cipherComboBox.setEnabled(true);
        cipherLabel.setEnabled(true);
        claveFinalLabel.setEnabled(true);
        claveInicialLabel.setEnabled(true);
        clavesComboBox.setEnabled(true);
        clavesPanel.setEnabled(true);
        entradaPanel.setEnabled(true);        
        NumeroClientesTextField.setEnabled(true);
        clientesLabel.setEnabled(true);
        modoComboBox.setEnabled(true);
        modoLabel.setEnabled(true);        
        plainComboBox.setEnabled(true);
        plainLabel.setEnabled(true);
        claveSizeComboBox.setEnabled(true);
        formatoClavesLabel.setEnabled(true);
        plainComboBox.setSelectedIndex(0);
        cipherComboBox.setSelectedIndex(0);
        modoComboBox.setSelectedIndex(0);
        monoCheckBox.setEnabled(true);
        monoCheckBox.setSelected(false);
    }//GEN-LAST:event_ServidorRadioButtonActionPerformed

    private void IPTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IPTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_IPTextFieldActionPerformed

    private void CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelarActionPerformed

        this.dispatchEvent(new java.awt.event.WindowEvent(this, java.awt.event.WindowEvent.WINDOW_CLOSING));
}//GEN-LAST:event_CancelarActionPerformed

    private void ClienteRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClienteRadioButtonActionPerformed
        IPTextField.setEnabled(true);
        IPLabel.setEnabled(true);
        clavesPanel.setEnabled(false);
        entradaPanel.setEnabled(false);
        cipherTextArea.setEnabled(false);
        ClaveFinalTextField.setEnabled(false);
        ClaveInicialTextField.setEnabled(false);
        plainTextArea.setEnabled(false);
        cipherComboBox.setEnabled(false);
        cipherLabel.setEnabled(false);
        claveFinalLabel.setEnabled(false);
        claveInicialLabel.setEnabled(false);
        clavesComboBox.setEnabled(false);
        clavesPanel.setEnabled(false);
        entradaPanel.setEnabled(false);        
        NumeroClientesTextField.setEnabled(false);
        clientesLabel.setEnabled(false);
        modoComboBox.setEnabled(false);
        modoLabel.setEnabled(false);
        plainBrowseButton.setEnabled(false);
        cipherBrowseButton.setEnabled(false);
        plainComboBox.setEnabled(false);
        plainLabel.setEnabled(false);
        claveSizeComboBox.setEnabled(false);
        formatoClavesLabel.setEnabled(false);
        monoCheckBox.setEnabled(false);
    }//GEN-LAST:event_ClienteRadioButtonActionPerformed

    private void EjecutarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EjecutarButtonActionPerformed
        if (ServidorRadioButton.isSelected() && ComprobarDatos()) {
            byte [] claveinicial = null;
            byte [] clavefinal = null;
            int op = 0;            

            if (ComprobarClaves()) {
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: claveinicial = Conversor.hexStringToByte(ClaveInicialTextField.getText());
                            clavefinal = Conversor.hexStringToByte(ClaveFinalTextField.getText());
                            break;

                    case 1: claveinicial = Conversor.stringToASCII(ClaveInicialTextField.getText());
                            clavefinal = Conversor.stringToASCII(ClaveFinalTextField.getText());
                }

                //calculamos aproximadamente el número de claves a probar por cliente para avisar si son demasiadas
                final long numClaves = getKeysToTry(claveinicial, clavefinal);
                int nC = 0;
                if (monoCheckBox.isSelected())
                    nC = 1;
                else
                    nC = Integer.parseInt(NumeroClientesTextField.getText());
                final int numClientes = nC;

                long clavesCliente = numClaves / numClientes;
                if ( clavesCliente >= 900000 )
                    op = JOptionPane.showConfirmDialog(this, Entorno.getTrans("Att.keySpaceWarMsg"),
                            Entorno.getTrans("gen.conf"), JOptionPane.YES_NO_OPTION);
                else if ( clavesCliente <= 0 ) {
                    //para que no cree el servidor
                    op = 1;
                    JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.badKeySpaceWarMsg"),
                            Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
                }
                
                final byte [] claveini = claveinicial;                
                final byte [] iv = pedirIV();

                if (op == 0 && iv != null) {
                    final byte [] plainBytes = getPlain();
                    final byte [] cipherBytes = getCipher();
                    yo = this;
                    if (monoCheckBox.isSelected()) {
                        Thread monoThread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                new MonoUI(wpadre, yo, plainBytes, cipherBytes, 
                                        claveini, numClaves,
                                        modoComboBox.getSelectedIndex(), iv);
                            }
                        });
                        wpadre.newThread(monoThread);
                        monoThread.start();                        
                    } else {
                        Thread servThread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                new ServUI(wpadre, yo, plainBytes, cipherBytes, numClientes, 
                                        claveini, numClaves,
                                        modoComboBox.getSelectedIndex(), iv);
                            }
                        });
                        wpadre.newThread(servThread);
                        servThread.start();
                    }
                    yo = null;
                }                
            }
        } else if (ClienteRadioButton.isSelected()) {
            if (IPTextField.getText().isEmpty())
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.ipWarMsg"),
                            Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            else {
                yo = this;
                Thread clientThread = new Thread(new Runnable() {
                    public void run() {
                        try {
                            new ClientUI(wpadre, yo, java.net.InetAddress.getByName(IPTextField.getText()));
                        } catch (java.net.UnknownHostException e) {
                            JOptionPane.showMessageDialog(null, Entorno.getTrans("Att.ipErrMsg"),
                            Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
                           Thread.currentThread().interrupt();
                        }
                    }
                });
                yo = null;
                wpadre.newThread(clientThread);
                clientThread.start();
            }
        }
    }//GEN-LAST:event_EjecutarButtonActionPerformed

    private void ContenidosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ContenidosActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ContenidosActionPerformed

    private void modoComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modoComboBoxActionPerformed
       
    }//GEN-LAST:event_modoComboBoxActionPerformed

    private void plainComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plainComboBoxActionPerformed
        switch (plainComboBox.getSelectedIndex()) {

            case 0:plainTextArea.setEditable(true);
                   plainTextArea.setText("");
                   plainBrowseButton.setEnabled(false);
                   break;

            case 1:plainTextArea.setEditable(true);
                   plainTextArea.setText("");
                   plainBrowseButton.setEnabled(false);
                   break;

            case 2:plainTextArea.setEditable(false);
                   plainTextArea.setText("");
                   plainBrowseButton.setEnabled(true);
        }
    }//GEN-LAST:event_plainComboBoxActionPerformed

    private void cipherComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cipherComboBoxActionPerformed
        switch (cipherComboBox.getSelectedIndex()) {

            case 0:cipherTextArea.setEditable(true);
                   cipherTextArea.setText("");
                   cipherBrowseButton.setEnabled(false);
                   break;

            case 1:cipherTextArea.setEditable(true);
                   cipherTextArea.setText("");
                   cipherBrowseButton.setEnabled(false);
                   break;

            case 2:cipherTextArea.setEditable(false);
                   cipherTextArea.setText("");
                   cipherBrowseButton.setEnabled(true);
        }
    }//GEN-LAST:event_cipherComboBoxActionPerformed

    private void plainBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plainBrowseButtonActionPerformed
        int resul = archivos.showSaveDialog(null);
        File archi= archivos.getSelectedFile();
        if (resul == JFileChooser.APPROVE_OPTION) plainTextArea.setText(archi.getPath());
    }//GEN-LAST:event_plainBrowseButtonActionPerformed

    private void cipherBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cipherBrowseButtonActionPerformed
        int resul = archivos.showSaveDialog(null);
        File archi= archivos.getSelectedFile();
        if (resul == JFileChooser.APPROVE_OPTION) cipherTextArea.setText(archi.getPath());
    }//GEN-LAST:event_cipherBrowseButtonActionPerformed

    private void menuCopiarClaroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuCopiarClaroActionPerformed
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringSelection ss = new StringSelection(plainTextArea.getText());
        cb.setContents(ss, ss);
    }//GEN-LAST:event_menuCopiarClaroActionPerformed

    private void menuPegarClaroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPegarClaroActionPerformed
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable t = cb.getContents(this);
      
        try{
            DataFlavor dataFlavorStringJava = new DataFlavor("application/x-java-serialized-object; class=java.lang.String");
            if (t.isDataFlavorSupported(dataFlavorStringJava)) {
            String texto = (String) t.getTransferData(dataFlavorStringJava);
            plainTextArea.setText(texto);}
        }
        catch (Exception e){
            JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.pasteErr"),
                    Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);

        }
    }//GEN-LAST:event_menuPegarClaroActionPerformed

    private void menuCopiarCifradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuCopiarCifradoActionPerformed
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringSelection ss = new StringSelection(cipherTextArea.getText());
        cb.setContents(ss, ss);
    }//GEN-LAST:event_menuCopiarCifradoActionPerformed

    private void menuPegarCifradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPegarCifradoActionPerformed
        Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable t = cb.getContents(this);
      
        try{
            DataFlavor dataFlavorStringJava = new DataFlavor("application/x-java-serialized-object; class=java.lang.String");
            if (t.isDataFlavorSupported(dataFlavorStringJava)) {
            String texto = (String) t.getTransferData(dataFlavorStringJava);
            cipherTextArea.setText(texto);}
        }
        catch (Exception e){
            JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.pasteErr"),
                    Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);

        }
    }//GEN-LAST:event_menuPegarCifradoActionPerformed

    private void plainTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_plainTextAreaKeyTyped
        switch (plainComboBox.getSelectedIndex()) {
             case 0: //ASCII
                 if (plainTextArea.getText().length() > 1024)
                     plainTextArea.setText(plainTextArea.getText().substring(0, 1024));
             break;
             case 1: //hexa
                 if (plainTextArea.getText().length() > 2048)
                     plainTextArea.setText(plainTextArea.getText().substring(0, 2048));
                 while (!ComprobarHexadecimal(plainTextArea.getText())) {
                     plainTextArea.setText(plainTextArea.getText().substring(0, plainTextArea.getText().length() - 1));
                 }
             break;
         }
    }//GEN-LAST:event_plainTextAreaKeyTyped

    private void plainTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_plainTextAreaKeyReleased
        plainTextAreaKeyTyped(evt);
    }//GEN-LAST:event_plainTextAreaKeyReleased

    private void cipherTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cipherTextAreaKeyTyped
        switch (cipherComboBox.getSelectedIndex()) {
             case 0: //base64
                 if (cipherTextArea.getText().length() > 1388)
                     cipherTextArea.setText(cipherTextArea.getText().substring(0, 1388));
             break;
             case 1: //hexa
                 if (cipherTextArea.getText().length() > 2080)
                     cipherTextArea.setText(cipherTextArea.getText().substring(0, 2080));
                 while (!ComprobarHexadecimal(cipherTextArea.getText())) {
                     cipherTextArea.setText(cipherTextArea.getText().substring(0, cipherTextArea.getText().length() - 1));
                 }
             break;
         }
    }//GEN-LAST:event_cipherTextAreaKeyTyped

    private void cipherTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cipherTextAreaKeyReleased
        cipherTextAreaKeyTyped(evt);
}//GEN-LAST:event_cipherTextAreaKeyReleased

    private void ClaveInicialTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ClaveInicialTextFieldKeyTyped
        switch (claveSizeComboBox.getSelectedIndex()) {
            case 0: //128 bits
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: //Hexa
                        if (ClaveInicialTextField.getText().length() > 32)
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, 32));
                        if (ClaveInicialTextField.getText().length() == 32 &&
                                ClaveFinalTextField.getText().length() == 32)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.hexStringToByte(ClaveInicialTextField.getText()), 
                                    Conversor.hexStringToByte(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                        while (!ComprobarHexadecimal(ClaveInicialTextField.getText())) {
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, ClaveInicialTextField.getText().length() - 1));
                        }
                    break;
                    case 1: //ASCII
                        if (ClaveInicialTextField.getText().length() > 16)
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, 16));
                        if (ClaveInicialTextField.getText().length() == 16 &&
                                ClaveFinalTextField.getText().length() == 16)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.stringToASCII(ClaveInicialTextField.getText()), 
                                    Conversor.stringToASCII(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                    break;
                }
            break;
            case 1: //192 bits
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: //Hexa
                        if (ClaveInicialTextField.getText().length() > 48)
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, 48));
                        if (ClaveInicialTextField.getText().length() == 48 &&
                                ClaveFinalTextField.getText().length() == 48)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.hexStringToByte(ClaveInicialTextField.getText()), 
                                    Conversor.hexStringToByte(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                        while (!ComprobarHexadecimal(ClaveInicialTextField.getText())) {
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, ClaveInicialTextField.getText().length() - 1));
                        }
                    break;
                    case 1: //ASCII
                        if (ClaveInicialTextField.getText().length() > 24)
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, 24));
                        if (ClaveInicialTextField.getText().length() == 24 &&
                                ClaveFinalTextField.getText().length() == 24)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.stringToASCII(ClaveInicialTextField.getText()), 
                                    Conversor.stringToASCII(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                    break;
                }
            break;
            case 2: //256 bits
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: //Hexa
                        if (ClaveInicialTextField.getText().length() > 64)
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, 64));
                        if (ClaveInicialTextField.getText().length() == 64 &&
                                ClaveFinalTextField.getText().length() == 64)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.hexStringToByte(ClaveInicialTextField.getText()), 
                                    Conversor.hexStringToByte(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                        while (!ComprobarHexadecimal(ClaveInicialTextField.getText())) {
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, ClaveInicialTextField.getText().length() - 1));
                        }
                    break;
                    case 1: //ASCII
                        if (ClaveInicialTextField.getText().length() > 32)
                            ClaveInicialTextField.setText(ClaveInicialTextField.getText().substring(0, 32));
                        if (ClaveInicialTextField.getText().length() == 32 &&
                                ClaveFinalTextField.getText().length() == 32)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.stringToASCII(ClaveInicialTextField.getText()), 
                                    Conversor.stringToASCII(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                    break;
                }
            break;
        }        
    }//GEN-LAST:event_ClaveInicialTextFieldKeyTyped

    private void ClaveInicialTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ClaveInicialTextFieldKeyReleased
        ClaveInicialTextFieldKeyTyped(evt);
    }//GEN-LAST:event_ClaveInicialTextFieldKeyReleased

    private void ClaveFinalTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ClaveFinalTextFieldKeyTyped
        switch (claveSizeComboBox.getSelectedIndex()) {
            case 0: //128 bits
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: //Hexa
                        if (ClaveFinalTextField.getText().length() > 32)
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, 32));
                        if (ClaveInicialTextField.getText().length() == 32 &&
                                ClaveFinalTextField.getText().length() == 32)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.hexStringToByte(ClaveInicialTextField.getText()), 
                                    Conversor.hexStringToByte(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                        while (!ComprobarHexadecimal(ClaveFinalTextField.getText())) {
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, ClaveFinalTextField.getText().length() - 1));
                        }
                    break;
                    case 1: //ASCII
                        if (ClaveFinalTextField.getText().length() > 16)
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, 16));
                        if (ClaveInicialTextField.getText().length() == 16 &&
                                ClaveFinalTextField.getText().length() == 16)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.stringToASCII(ClaveInicialTextField.getText()), 
                                    Conversor.stringToASCII(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                    break;
                }                
            break;
            case 1: //192 bits
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: //Hexa
                        if (ClaveFinalTextField.getText().length() > 48)
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, 48));
                        if (ClaveInicialTextField.getText().length() == 48 &&
                                ClaveFinalTextField.getText().length() == 48)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.hexStringToByte(ClaveInicialTextField.getText()), 
                                    Conversor.hexStringToByte(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                        while (!ComprobarHexadecimal(ClaveFinalTextField.getText())) {
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, ClaveFinalTextField.getText().length() - 1));
                        }
                    break;
                    case 1: //ASCII
                        if (ClaveFinalTextField.getText().length() > 24)
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, 24));
                        if (ClaveInicialTextField.getText().length() == 24 &&
                                ClaveFinalTextField.getText().length() == 24)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.stringToASCII(ClaveInicialTextField.getText()), 
                                    Conversor.stringToASCII(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                    break;
                }
            break;
            case 2: //256 bits
                switch (clavesComboBox.getSelectedIndex()) {
                    case 0: //Hexa
                        if (ClaveFinalTextField.getText().length() > 64)
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, 64));
                        if (ClaveInicialTextField.getText().length() == 64 &&
                                ClaveFinalTextField.getText().length() == 64)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.hexStringToByte(ClaveInicialTextField.getText()), 
                                    Conversor.hexStringToByte(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                        while (!ComprobarHexadecimal(ClaveFinalTextField.getText())) {
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, ClaveFinalTextField.getText().length() - 1));
                        }
                    break;
                    case 1: //ASCII
                        if (ClaveFinalTextField.getText().length() > 32)
                            ClaveFinalTextField.setText(ClaveFinalTextField.getText().substring(0, 32));
                        if (ClaveInicialTextField.getText().length() == 32 &&
                                ClaveFinalTextField.getText().length() == 32)
                            nKeysLabel.setText(Long.toString(getKeysToTry(
                                    Conversor.stringToASCII(ClaveInicialTextField.getText()), 
                                    Conversor.stringToASCII(ClaveFinalTextField.getText()))));
                        else {
                            nKeysLabel.setText("");
                            nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));                            
                        }
                    break;
                }
            break;
        }
        
    }//GEN-LAST:event_ClaveFinalTextFieldKeyTyped

    private void ClaveFinalTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ClaveFinalTextFieldKeyReleased
        ClaveFinalTextFieldKeyTyped(evt);
    }//GEN-LAST:event_ClaveFinalTextFieldKeyReleased

    private void clavesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clavesComboBoxActionPerformed
        ClaveInicialTextFieldKeyTyped(null);
        ClaveFinalTextFieldKeyTyped(null);
    }//GEN-LAST:event_clavesComboBoxActionPerformed

    private void claveSizeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_claveSizeComboBoxActionPerformed
        ClaveInicialTextFieldKeyTyped(null);
        ClaveFinalTextFieldKeyTyped(null);
    }//GEN-LAST:event_claveSizeComboBoxActionPerformed

    private void nKeysLabelPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_nKeysLabelPropertyChange
        if (evt.getPropertyName().equals("text")) {            
            if (evt.getNewValue().equals("1"))
                nKeysTxtLabel.setText(Entorno.getTrans("Net.nKey"));            
            else if (evt.getNewValue().equals("0")) {
                nKeysLabel.setText("");
                nKeysTxtLabel.setText(Entorno.getTrans("Att.noKeys"));
            } else if (!evt.getNewValue().equals(""))
                nKeysTxtLabel.setText(Entorno.getTrans("Net.nKeys"));            
        }
    }//GEN-LAST:event_nKeysLabelPropertyChange

    private void monoCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monoCheckBoxActionPerformed
        if (monoCheckBox.isSelected())
            NumeroClientesTextField.setEnabled(false);
        else NumeroClientesTextField.setEnabled(true);
    }//GEN-LAST:event_monoCheckBoxActionPerformed

    private void ClaveFinalTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClaveFinalTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ClaveFinalTextFieldActionPerformed

    private long getKeysToTry (byte [] iniClave, byte [] finClave) {
         int len = iniClave.length;
         long numKeys = 0L;
         boolean out = false;         
         int resta = 0;
         int lim = len - 8; //posicion a partir de la que cabe en long

         for (int i = 0; ((i < len) && !out); i++) {
             resta = (Conversor.byteToInt(finClave[i]) - Conversor.byteToInt(iniClave[i]));
             /*
              * Un long es de como máximo 8 bytes, hasta el byte 8 la resta
              * debe ser 0. El valor máximo de un long es 7FFFFFFFFFFFFFFF,
              * por lo que en el byte 8 la resta debe ser 127 (7F) o menor
              */
             if ( (i < lim) && (resta != 0) ) out = true;             
             else if ( (i == lim) && (resta > 127) ) out = true;
             else if ( (i >= lim) && (resta < 0) ) out = true;
             else if ( (i >= lim) && (resta >= 0) ) {                 
                 numKeys <<= 8;
                 numKeys += resta;
             }                                  
         }
         
         //si ya hemos llegado al máximo, la suma posterior se saldrá de los límites
         if (numKeys == 9223372036854775807L) out = true;
         else
             //como incluimos en la prueba la clave inicial y final, hay que sumar uno al resultado
            numKeys++;       
         
         //si el número de claves supera los límites de long, devolvemos 0
         if (out) numKeys=0;
         
         return numKeys;
     }

    /**
     * Función que devuelve el primer bloque de lo que se haya introducido en el
     * texto en claro. Si el texto en claro era menos de 16 bytes, se llevará
     * a cabo el relleno mediante la función de relleno para ECB/CBC. Si es
     * mayor, no será necesario
     * @return El primer bloque del texto en claro con pad (si procede)
     */
    private byte [] getPlain () {
        byte [] aux = null;
        switch (plainComboBox.getSelectedIndex()) {

            case 0:
                if (plainTextArea.getText().length() < 16) {
                    aux = Conversor.stringToASCII(plainTextArea.getText());
                    aux = Conversor.pad(aux, 16);
                } else
                    try {
                        aux = Conversor.stringToASCII(plainTextArea.getText(0,16));
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.plainGetErr"),
                            Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
                    }
                break;

            case 1:
                if (plainTextArea.getText().length() < 32) {
                    aux = Conversor.hexStringToByte(plainTextArea.getText());
                    aux = Conversor.pad(aux, 16);
                } else
                    try {
                        aux = Conversor.hexStringToByte(plainTextArea.getText(0, 32));
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.plainGetErr"),
                            Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
                    }
                break;

            case 2:
                aux = getBytesArchivo(plainTextArea.getText());
                if (aux.length < 16) aux = Conversor.pad(aux, 16);

        }
        return aux;
    }

    private byte [] getBytesArchivo (String ruta) {
        byte [] aux = null;
        try {
         aux = ReadFileIntoByteArray.getBytesFromFile(new File(ruta), 16);
        }
        catch (Exception e){
            JOptionPane.showMessageDialog(this, Entorno.getTrans("gen.fileErr") +
                    ruta, Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
        }
        return aux;
    }

    private byte [] getCipher() {
        byte [] aux = null;
        switch (cipherComboBox.getSelectedIndex()) {

            case 0:
                aux = Base64.decode(cipherTextArea.getText());
                if (aux.length < 16) aux = Conversor.pad(aux, 16);
                else if (aux.length > 16) {
                    byte [] aux2 = aux;
                    aux = new byte[16];
                    System.arraycopy(aux2, 0, aux, 0, 16);                    
                }
                break;

            case 1:
                if (cipherTextArea.getText().length() < 32) {
                    aux = Conversor.hexStringToByte(cipherTextArea.getText());
                    aux = Conversor.pad(aux, 16);
                } else
                    try {
                        aux = Conversor.hexStringToByte(cipherTextArea.getText(0, 32));
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.cipherGetErr"),
                            Entorno.getTrans("gen.err"), JOptionPane.ERROR_MESSAGE);
                    }
                break;

            case 2:
                aux = getBytesArchivo(cipherTextArea.getText());
                if (aux.length < 16) aux = Conversor.pad(aux, 16);
                
        }
        return aux;
    }

    private byte [] pedirIV () {
        boolean cont = true;
        String res = "0";
        //sólo se entra si el modo es CBC
        if (modoComboBox.getSelectedIndex() == 1)
            while (cont) {
                res = JOptionPane.showInputDialog(this, Entorno.getTrans("AES.introIVMsg"),
                        Entorno.getTrans("AES.introIVTit"), JOptionPane.QUESTION_MESSAGE);
                if (res == null)
                    cont = false;
                else
                    cont = !comprobarIV(res);
            }

        if (res == null) return null;
        return Conversor.hexStringToByte(res);
    }

    private boolean comprobarIV (String iv) {
        boolean aux = true;

        if (aux && iv.isEmpty()) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("AES.introIVWarMsg"),
                    Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if (aux && (iv.length() != 32)) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("AES.lenIVWarMsg"),
                    Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if (aux && !ComprobarHexadecimal(iv)) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("AES.hexIVWarMsg"),
                    Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        return aux;
    }

    private boolean ComprobarHexadecimal (String cadena){

    boolean resul = true;

    for (int i = 0; i < cadena.length() ; i++){

      if ( ((cadena.charAt(i) >= 'A') && (cadena.charAt(i) <= 'F')) ||
          ((cadena.charAt(i) >= 'a') && (cadena.charAt(i) <= 'f')) ||
          ((cadena.charAt(i) >= '0') && (cadena.charAt(i) <= '9')));
      else {
          resul=false;
      }
    }

    return resul;
    }

    private boolean ComprobarClaves () {
        boolean aux = true;
        int indexFormat = clavesComboBox.getSelectedIndex();
        int indexSize = claveSizeComboBox.getSelectedIndex();

        if ( aux && ClaveInicialTextField.getText().isEmpty() ) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("AES.fillWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && ClaveFinalTextField.getText().isEmpty() ) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("AES.fillWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (indexFormat == 0) && !ComprobarHexadecimal(ClaveInicialTextField.getText() )) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1HexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if ( aux && (indexFormat == 0) && !ComprobarHexadecimal(ClaveFinalTextField.getText()) ) {
            aux = false;
            JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2HexWarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
        }

        if (aux && (indexSize == 0) ) {

            if (aux && (indexFormat == 0) && (ClaveInicialTextField.getText().length() != 32) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1HexLen32WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if ( aux && (indexFormat == 0) && (ClaveFinalTextField.getText().length() != 32) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2HexLen32WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if (aux && (indexFormat == 1) && (ClaveInicialTextField.getText().length() != 16) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1AsciLen16WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if (aux && (indexFormat == 1) && (ClaveFinalTextField.getText().length() != 16) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2AsciLen16WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }
        }

        if ( aux && (indexSize == 1) ) {

            if (aux && (indexFormat == 0) && (ClaveInicialTextField.getText().length() != 48) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1HexLen48WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if ( aux && (indexFormat == 0) && (ClaveFinalTextField.getText().length() != 48) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2HexLen48WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if (aux && (indexFormat == 1) && (ClaveInicialTextField.getText().length() != 24) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1AsciLen24WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if (aux && (indexFormat == 1) && (ClaveFinalTextField.getText().length() != 24) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2AsciLen24WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }
        }

        if ( aux && (indexSize == 2) ) {

            if (aux && (indexFormat == 0) && (ClaveInicialTextField.getText().length() != 64) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1HexLen64WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if ( aux && (indexFormat == 0) && (ClaveFinalTextField.getText().length() != 64) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2HexLen64WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if (aux && (indexFormat == 1) && (ClaveInicialTextField.getText().length() != 32) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key1AsciLen32WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }

            if (aux && (indexFormat == 1) && (ClaveFinalTextField.getText().length() != 32) ) {
                aux = false;
                JOptionPane.showMessageDialog(this, Entorno.getTrans("Att.key2AsciLen32WarMsg"),
                   Entorno.getTrans("gen.war"), JOptionPane.WARNING_MESSAGE);
            }
        }
        return aux;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonInfo;
    private javax.swing.JButton Cancelar;
    private javax.swing.JTextField ClaveFinalTextField;
    private javax.swing.JTextField ClaveInicialTextField;
    private javax.swing.JRadioButton ClienteRadioButton;
    private javax.swing.JMenuItem Contenidos;
    private javax.swing.JButton EjecutarButton;
    private javax.swing.JLabel IPLabel;
    private javax.swing.JTextField IPTextField;
    private javax.swing.JTextField NumeroClientesTextField;
    private javax.swing.JMenuItem Salir;
    private javax.swing.JRadioButton ServidorRadioButton;
    private javax.swing.JMenuItem acercade;
    private javax.swing.JMenuBar cifrarMenuBarMain;
    private javax.swing.JButton cipherBrowseButton;
    private javax.swing.JComboBox cipherComboBox;
    private javax.swing.JLabel cipherLabel;
    private javax.swing.JTextArea cipherTextArea;
    private javax.swing.JLabel claveFinalLabel;
    private javax.swing.JLabel claveInicialLabel;
    private javax.swing.JComboBox claveSizeComboBox;
    private javax.swing.JComboBox clavesComboBox;
    private javax.swing.JPanel clavesPanel;
    private javax.swing.JLabel clientesLabel;
    private javax.swing.JPanel entradaPanel;
    private javax.swing.JLabel formatoClavesLabel;
    private javax.swing.JLabel funcLabel;
    private javax.swing.JPanel funcionamientoPanel;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JMenu mainMenuArchivo;
    private javax.swing.JMenu mainMenuAyuda;
    private javax.swing.JMenu mainMenuEditar;
    private javax.swing.JMenuItem menuCopiarCifrado;
    private javax.swing.JMenuItem menuCopiarClaro;
    private javax.swing.JMenuItem menuPegarCifrado;
    private javax.swing.JMenuItem menuPegarClaro;
    private javax.swing.JComboBox modoComboBox;
    private javax.swing.JLabel modoLabel;
    private javax.swing.JCheckBox monoCheckBox;
    private javax.swing.JLabel nKeysLabel;
    private javax.swing.JLabel nKeysTxtLabel;
    private javax.swing.JButton plainBrowseButton;
    private javax.swing.JComboBox plainComboBox;
    private javax.swing.JLabel plainLabel;
    private javax.swing.JTextArea plainTextArea;
    // End of variables declaration//GEN-END:variables

}
